{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Read data function examples for basic DEA models\n",
    "在此示範如何使用csv2dict()、csv2dict_sep()來讀取要被衡量的資料，以利後續放入DEA主程式時使用，並顯示它們最終形成的資料形式。<br>\n",
    "\n",
    "※示範程式碼及csv資料存放於[這裡](https://github.com/wurmen/DEA/tree/master/Functions/basic_DEA_data%26code)，可自行下載測試。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "#導入存放csv2dict()、csv2dict_sep()的py檔(在此名為DEA)\n",
    "import DEA"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# csv2dict()\n",
    "-------\n",
    "## Exampl1\n",
    "當產出與投入資料放置同一csv檔時，並且**<span style=\"color:red\">不指定</span>**以2~4行當成投入資料，5~8行當成產出資料。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU,X,Y=DEA.csv2dict(\"data.csv\",in_range=[2,4],out_range=[5,8],assign=False) # return DMU、X、Y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['A', 'B', 'C', 'D', 'E', 'F', 'G', 'I', 'J', 'K', 'L', 'M', 'O']\n"
     ]
    }
   ],
   "source": [
    "print(DMU) # DMU list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [392.0, 1.0, 8259.0], 'B': [381.0, 2.0, 9628.0], 'C': [2673.0, 3.0, 70923.0], 'D': [282.0, 4.0, 9683.0], 'E': [1608.0, 5.0, 40630.0], 'F': [2074.0, 6.0, 47420.0], 'G': [75.0, 7.0, 7115.0], 'I': [458.0, 8.0, 10177.0], 'J': [1722.0, 9.0, 29124.0], 'K': [400.0, 10.0, 8987.0], 'L': [1217.0, 11.0, 34680.0], 'M': [2532.0, 12.0, 51536.0], 'O': [1303.0, 13.0, 32683.0]}\n"
     ]
    }
   ],
   "source": [
    "print(X) # input data dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [23756.0, 4.0, 2.0, 870.0], 'B': [24183.0, 5.0, 3.0, 1359.0], 'C': [163483.0, 6.0, 4.0, 12449.0], 'D': [10370.0, 7.0, 5.0, 509.0], 'E': [99047.0, 8.0, 6.0, 3726.0], 'F': [128635.0, 9.0, 7.0, 9214.0], 'G': [11962.0, 10.0, 8.0, 536.0], 'I': [32436.0, 11.0, 9.0, 1462.0], 'J': [83862.0, 12.0, 10.0, 6337.0], 'K': [14618.0, 13.0, 11.0, 785.0], 'L': [99636.0, 14.0, 12.0, 6597.0], 'M': [135480.0, 15.0, 13.0, 10928.0], 'O': [74106.0, 16.0, 14.0, 4258.0]}\n"
     ]
    }
   ],
   "source": [
    "print(Y) # output data dict"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example2\n",
    "當產出與投入資料放置同一csv檔時，並且**<span style=\"color:red\">指定</span>**以2、4行當成投入資料，5、8行當成產出資料。\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU,X,Y=DEA.csv2dict(\"data.csv\",in_range=[2,4],out_range=[5,8],assign=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['A', 'B', 'C', 'D', 'E', 'F', 'G', 'I', 'J', 'K', 'L', 'M', 'O']\n"
     ]
    }
   ],
   "source": [
    "print(DMU)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [392.0, 8259.0], 'B': [381.0, 9628.0], 'C': [2673.0, 70923.0], 'D': [282.0, 9683.0], 'E': [1608.0, 40630.0], 'F': [2074.0, 47420.0], 'G': [75.0, 7115.0], 'I': [458.0, 10177.0], 'J': [1722.0, 29124.0], 'K': [400.0, 8987.0], 'L': [1217.0, 34680.0], 'M': [2532.0, 51536.0], 'O': [1303.0, 32683.0]}\n"
     ]
    }
   ],
   "source": [
    "print(X)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [23756.0, 870.0], 'B': [24183.0, 1359.0], 'C': [163483.0, 12449.0], 'D': [10370.0, 509.0], 'E': [99047.0, 3726.0], 'F': [128635.0, 9214.0], 'G': [11962.0, 536.0], 'I': [32436.0, 1462.0], 'J': [83862.0, 6337.0], 'K': [14618.0, 785.0], 'L': [99636.0, 6597.0], 'M': [135480.0, 10928.0], 'O': [74106.0, 4258.0]}\n"
     ]
    }
   ],
   "source": [
    "print(Y)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# csv2dict_sep()\n",
    "---------------------\n",
    "## Example1\n",
    "當產出與投入分別放在不同檔案時，且**<span style=\"color:red\">不指定</span>**投入或產出資料。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU, X = DEA.csv2dict_sep(\"data_input.csv\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['A', 'B', 'C', 'D', 'E', 'F', 'G', 'I', 'J', 'K', 'L', 'M', 'O']\n"
     ]
    }
   ],
   "source": [
    "print(DMU)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [392.0, 8259.0], 'B': [381.0, 9628.0], 'C': [2673.0, 70923.0], 'D': [282.0, 9683.0], 'E': [1608.0, 40630.0], 'F': [2074.0, 47420.0], 'G': [75.0, 7115.0], 'I': [458.0, 10177.0], 'J': [1722.0, 29124.0], 'K': [400.0, 8987.0], 'L': [1217.0, 34680.0], 'M': [2532.0, 51536.0], 'O': [1303.0, 32683.0]}\n"
     ]
    }
   ],
   "source": [
    "print(X)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example2\n",
    "當產出與投入分別放在不同檔案時，且**<span style=\"color:red\">指定</span>**投入或產出資料。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "DMU, Y = DEA.csv2dict_sep(\"data_output.csv\", vrange =[2,4], assign=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'A': [392.0, 8259.0], 'B': [381.0, 9628.0], 'C': [2673.0, 70923.0], 'D': [282.0, 9683.0], 'E': [1608.0, 40630.0], 'F': [2074.0, 47420.0], 'G': [75.0, 7115.0], 'I': [458.0, 10177.0], 'J': [1722.0, 29124.0], 'K': [400.0, 8987.0], 'L': [1217.0, 34680.0], 'M': [2532.0, 51536.0], 'O': [1303.0, 32683.0]}\n"
     ]
    }
   ],
   "source": [
    "print(X)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
